// Copyright 叶湘 ( weixin:yexiang841, email:yexiang841@qq.com ), Shitouren Studio. All Rights Reserved.

#include "Pawn/Q3D_CPPA_Pawn_FighterEnemy_ClassA.h"
#include "Logger/Q3D_CPPU_Logger.h"

// Called when the game starts or when spawned
void AQ3D_CPPA_Pawn_FighterEnemy_ClassA::BeginPlay()
{
    Super::BeginPlay();

    // 基类的 BeginPlay() 通过调用本类的 Q3D_IF_PropertyState_InitDT_Get() 向 PropertyState 中写入了初始数据

    // 绑定一些属性关联
    this->Ptr_C_PropertyState->Q3D_F_Property_Bind_Max_To_Now(EQ3D_CPPE_PropertyName::LIVE_HP_MAX, EQ3D_CPPE_PropertyName::LIVE_HP_NOW);
    this->Ptr_C_PropertyState->Q3D_F_Property_Bind_Max_To_Now(EQ3D_CPPE_PropertyName::MANA_MP_MAX, EQ3D_CPPE_PropertyName::MANA_MP_NOW);
}

void AQ3D_CPPA_Pawn_FighterEnemy_ClassA::Q3D_IF_PropertyState_InitDT_Get_Implementation(UDataTable *&ptr_dt_property_init) const
{
    // Owner 已经从外部对 Ptr_DT_PropertyInit 进行了赋值，优先级最高，直接使用
    if (this->Ptr_DT_PropertyInit)
    {
        ptr_dt_property_init = this->Ptr_DT_PropertyInit;
        Q3D_LOG(Log, "DT_Load_From_Ptr_DT_PropertyInit");
        return;
    }

    // 子类未赋值DT，就用默认的
    const FString string_dt_path_tmp = "DataTable'/Q3D_Lib/Q3D/Property/Q3D_DT_Property_Pawn_FighterEnemy_ClassA.Q3D_DT_Property_Pawn_FighterEnemy_ClassA'";

    // 结构体
    // EQ3D_CPPE_PropertyName Enum_PropertyName;
    // bool Bool_Active;
    // int32 Int_Min;
    // int32 Int_Max;
    // EQ3D_CPPE_PropertyInit Enum_PropertyInit;
    // int32 Int_Value;

    UDataTable *ptr_dt_property_init_tmp;

    // DT的一种读法
    // static ConstructorHelpers::FObjectFinder<UDataTable> finder_tmp( string_dt_path_tmp );
    // if( finder_tmp.Object ){ ptr_dt_property_init_tmp = ( UDataTable* )( finder_tmp.Object ); }

    // DT的另一种读法
    ptr_dt_property_init_tmp = LoadObject<UDataTable>(NULL, UTF8_TO_TCHAR(*string_dt_path_tmp));

    if (!ptr_dt_property_init_tmp)
    {
        Q3D_LOG(Warning, "DT_Missed_From_[" + string_dt_path_tmp + "]");
        ptr_dt_property_init = nullptr;
        return;
    }
    ptr_dt_property_init = ptr_dt_property_init_tmp;
    Q3D_LOG(Log, "DT_Load_From_[" + string_dt_path_tmp + "]");
    return;
}
